'''
Created on 31/08/2012

@author: Caio Alves
'''
from django import template
from django.utils.numberformat import format
from django.contrib.humanize.templatetags.humanize import intcomma

register = template.Library()

def formata(value):
    #string = format(float(value), ',', 2, 3, '.')
    string = intcomma(float(value))
    return string+'0'

def reduz(value, qtd):
    tam = int(qtd)
    if value.__len__() > tam:
        string = value[:tam]
        string = string + '...'
        return string
    else:
        return value

register.filter('formata', formata)
register.filter('reduz', reduz)